/*
Author: Surpass-HC
Source: https://gitee.com/hxchuan000/clpc-1
Mail: surpass-hc@qq.com
*/
#pragma once
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <cstring.h>
#include <typecomm.h>

enum CL_LOG_LEVEL_ENUM
{
    CL_LOG_LEV_FATAL = 0,
    CL_LOG_LEV_ERROR,
    CL_LOG_LEV_WARN,
    CL_LOG_LEV_INFO,
    CL_LOG_LEV_DEBUG,
    CL_LOG_LEV_TRACE,
    CL_LOG_LEV_MAX
};

typedef void (*logWayFun)(void *waydata, const char *logstr, int strlen);
struct clogWayInfo
{
    logWayFun fun;
    const char *wayName;
    void *wayUserData;
};
struct clogPrintInfo
{
    int loglev;
    int printMaxLen;
    struct clogWayInfo logway[5];
    pthread_mutex_t logLock;
    // uint32_t logFileSize;
    // uint8_t logFileNumb;
    // uint8_t logFileFlush;
    // cstring logfile;
};
typedef struct clogPrintInfo clogPrintInfo;
#define clogPrintMinSize (128)
#define clogPrintMaxSize (32 * 1024)

int clogPrintCfgLev(clogPrintInfo *logprt, int cfglev);
int clogPrintCfgLen(clogPrintInfo *logprt, int cfglen);
int clogPrintCfgWay(clogPrintInfo *logprt, struct clogWayInfo cfgval);
int clogPrintInit(clogPrintInfo *logprt, int cfglev, int cfglen);
int clogPrintQuit(clogPrintInfo *logprt);
int __attribute__((format(printf, 5, 6))) clogPrintFunc(clogPrintInfo *logprt, int lev, const char *fstr, int line, const char *fmt, ...);
